import connDB

##根据dwd建表语句，创建dm表建表语句，修改表名即可
def midToDwdTableName(midSchema, midTableName, dwdSchema, dwdTableName,attibutes):
    # 创建连接
    connDwd = connDB.create_connection(**connDB.dwr_prd_config)
    if connDwd:
        queryMidCreateTable = f"select pg_get_tabledef('{midSchema}.{midTableName}');"
        midCreateTable=connDB.fetch_data(connDwd, queryMidCreateTable)
        if midCreateTable:
            dwdCreateTable = midCreateTable[0][0]
            dwdCreateTable = dwdCreateTable.replace(midSchema,dwdSchema,1)
            dwdCreateTable = dwdCreateTable.replace(midTableName,dwdTableName)
            print(dwdCreateTable)
        connDwd.close()
        print("数据库连接已关闭")
if __name__ == "__main__":
    #dwd schema
    midSchema = "mrg_mid"
    # dm schema
    dwdSchema= 'mrg'
    #dwd 表名
    midTableName="dwi_mrg_org_reln_info_d_f_mid"
    # dm 表名
    dwdTableName="dwd_ft_mrg_org_reln_info_d_f"
    # 需要删除的dm字段
    attibutes=[]
    midToDwdTableName(midSchema, midTableName, dwdSchema, dwdTableName, attibutes)